package com.xindong.paking.controller;


import com.xindong.paking.entity.TbMessage;
import com.xindong.paking.entity.vo.TbMessageVo;
import com.xindong.paking.service.TbMessageService;
import com.xindong.paking.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author huangshengce
 * @since 2023-01-11
 */
@Api(tags = "信息模块")
@RestController
@RequestMapping("/message")
public class TbMessageController {

    @Autowired
    private TbMessageService tbMessageService;

    @ApiOperation("发信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adminId", value = "发送管理员"),
            @ApiImplicitParam(name = "recipientId", value = "接受用户"),
            @ApiImplicitParam(name = "content", value = "内容"),
            @ApiImplicitParam(name = "title", value = "标题（0：未支付订单，1：广告）"),
    })
    @PostMapping("/add")
    public Result add(@RequestBody TbMessageVo tbMessageVo) {
        TbMessage tbMessage = new TbMessage();
        BeanUtils.copyProperties(tbMessageVo, tbMessage);
        return tbMessageService.addMessage(tbMessage);
    }



    @ApiOperation("分页条件查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小")
    })
    @GetMapping("list")
    public Result list(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize) {
        return tbMessageService.list(page, pageSize);
    }




    @ApiOperation("删除信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "信息id")
    })
    @DeleteMapping("/delete")
    public Result delete(@RequestParam("id") Integer id) {
        return tbMessageService.deleteMessage(id);
    }



    @ApiOperation("修改信息状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "信息id")
    })
    @PutMapping("updateStatus")
    public Result update(@RequestParam("id") Integer id) {
        return tbMessageService.updateMessageStatus(id);
    }

}

